Ext.define('Emp.controller.InitController', {
    extend: 'Ext.app.Controller',
	
    requires: [
    	'Emp.ux.window.MessageBox'
    ],
    
    ajaxTotalCount: 1,
    ajaxCount: 0,
    
    init: function() {
    	Ext.getBody().mask('系统初始化中...');
    	var me = this;
    	Ext.BLANK_IMAGE_URL = PATH + '/' + Emp.ext + '/resources/themes/images/default/tree/s.gif';
		Ext.show = function() {
		    var msgCt;
		    function createBox(t, s) {
		       return '<div class="msg"><h3>' + t + '</h3><p>' + s + '</p></div>';
		    }
		    return {
		        msg: function(title, format) {
		            if(!msgCt){
		                msgCt = Ext.core.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
		            }
		            var s = Ext.String.format.apply(String, Array.prototype.slice.call(arguments, 1));
		            var m = Ext.core.DomHelper.append(msgCt, createBox(title, s), true);
		            m.hide();
		            m.slideIn('t').ghost("t", {delay: 1000, remove: true});
		        },
		        init: function() {}
		    };
		}();
    	
		Ext.Ajax.request({
			method: 'get',
			url: PATH + '/dictionary/initDictionary',
			success: function(response, options) {
				me.ajaxCount++;
				var result = Ext.decode(response.responseText);
				if (result.success) {
					Emp.dictionary = result.datas;
					if(me.ajaxCount === me.ajaxTotalCount) {
						me.initViewport();
					}
				} else {
					Ext.getBody().unmask();
					Ext.Msg.show({
						title: '提示',
						msg: result.message,
						buttons: Ext.Msg.OK,
						icon: Ext.Msg.ERROR
					});
				}
			},
			failure: function(response, options) {
				Ext.getBody().unmask();
				Emp.msg.ajaxFailure(response, options);
			}
		});
    },
    
    initViewport: function() {
    	this.application.getController('ViewportController').init();
		Ext.create('Emp.view.Viewport');
		Ext.getBody().unmask();
    }
});